home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15500 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.duke.edu!stking
  2. From: stking@acpub.duke.edu (Steve King)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem w/simple linked list
  5. Date: 19 Apr 1996 12:31:05 GMT
  6. Organization: Duke University, Durham, NC, USA
  7. Message-ID: <4l8129$23e@news.duke.edu>
  8. References: <4l5eha$5qa@news.duke.edu> <3176E48C.3E7B@willows.com>
  9. NNTP-Posting-Host: godzilla5.acpub.duke.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. : >    }
  13. : >    previous = walk;
  14. : >    return(NULL);
  15.  
  16. : You'll note that within the for loop previous is always NULL so I think
  17. : you want to move previous = walk into the loop.
  18.  
  19. Yup. I feel like an idiot for not catching this myself. Many thanks
  20. to you and everyone else who pointed this out....
  21.  
  22. : However this still 
  23. : leaves you with one problem; what happens if the first node is the correct
  24. : one?  But because you have only a singlely linked list it will be difficult
  25. : to properly execute if you still want to use the return value of the function
  26. : as the indicator.  So there are two possible solutions:
  27.  
  28. (Solution 1 deleted -- don't really need the advantages
  29. of a doubley-linked list for what I'm trying to do).
  30.  
  31. But this....
  32.  
  33. : 2. if you want to keep the singlely linked list then you must take into 
  34. : account the special situation where the first node is the matching one.
  35. : The simplest way I can think of is to move the delete code into the
  36. : FindInList routine:
  37. :         ...
  38. :     if (strcmp(walk->patient.name,name) == 0)
  39. :         {
  40. :         if ( previous )
  41. :             previous->next = walk->next;
  42. :         free ( walk );
  43. :             return( 1 );
  44. :         }
  45. :     ...
  46. :     return ( 0 );
  47.  
  48.  
  49. I *like*!  Hmmm. I was thinking about just doing something like
  50. using "memset()" to fill the head structure with garbage, or
  51. 0's, but your second solution really impresses me as being a
  52. clean way to handle this.
  53.  
  54. Thanks, man. And again, to everyone who took his or her time to
  55. write.
  56.  
  57.  
  58.  
  59. ======================================================================
  60. *stking@acpub.duke.edu*| Such as they are, these are my opinions only;
  61.     *919-286-4476*     | not my employer's or internet provider's....
  62. ======================================================================
  63.  
  64.